使用来自 Social Mention 的小部件脚本——http : //socialmention.com/tools/ 。尝试通过添加输入框进行修改,以允许用户更改社交媒体主题(var smSearchPhrase)。我创建了一个函数 [smSearch()] 来检索用户数据 (smTopic),将其分配给一个新变量 (var newTopic),然后将该值分配给 var smSearchPhrase。分配不工作。
该函数似乎根据通过警报观察到的值起作用,但是,我无法弄清楚如何将 var newTopic 中的值分配给脚本内的 var smSearchPhrase。我通过在函数中放置脚本进行了实验,但这也不起作用。任何帮助表示赞赏。
如果我未能包含所有必要的信息,请告知。感谢您的任何帮助。
HTML:
<form>
<label for="smTopic">Enter topic:</label>
<input type="text" id="smTopic">
<button onclick="smSearch()">Submit</button>
<input type="reset">
</form>
功能:(包括检查值的警报)
function smSearch(){
var newTopic=document.getElementById("smTopic").value;
if(newTopic === ""){
alert("Please enter new social media topic.");
}else{
alert("New topic: " + newTopic);
smSearchPhrase = newTopic;
alert("Value of smSearchPhrase: " + smSearchPhrase);
}
脚本:var smSearchPhrase in original 已赋值,例如 var smSearchPhrase = '社会提及';
<script type="text/javascript">
// search phrase (replace this)
var smSearchPhrase;
// title (optional)
var smTitle = 'Realtime Buzz';
// items per page
var smItemsPerPage = 7;
// show or hide user profile images
var smShowUserImages = true;
// widget font size in pixels
var smFontSize = 11;
// height of the widget
var smWidgetHeight = 800;
// sources (optional, comment out for "all")
//var smSources = ['twitter', 'facebook', 'googleblog', 'identica'];
</script>
<script type="text/javascript" language="javascript" src="http://socialmention.s3.amazonaws.com/buzz_widget/buzz.js"></script>