javascript innerhtml return value
javascript innerhtml return value
我很难理解这一点。我有这个位码:
document.getElementById("widget-container-1").innerHTML="<div class='title'>Select town: "+
"<select id='drop'>"+
"<option name='Auckland' value='Auckland'>Auckland</option>"+
"<option name='Christchurch' value='Christchurch'>Christchurch</option>"+
"<option name='Dunedin' value='Dunedin'>Dunedin</option>"+
"<option>Hamilton</option>"+
"<option>Tauranga</option>"+
"<option>Wellington</option>"+
"</select><br />"+
"<button id='update' name='update' onClick='"this, _refreshWeatherDisplay(test);''">update</button></div>"+
"<div class='monitor'>Sort by"+
"<input id='radio' name='input' type='radio' value='0' >town"+
"<input id='radio' name='input' type='radio' value='1' >max temp"+
"<div class='section'>test</div></div>";
select = document.getElementById("drop");
select.onchange = function(){
_checkNewTown(this.options[this.selectedIndex].text);
};
我想获得数据并执行另一个功能:
var _checkNewTown = function(ntown){
alert(this.selectedIndex);
}
但是,在-checkNewTown函数中是keep return undefined。当我想提醒它的时候,按钮不工作。
var _refreshWeatherDisplay = function(weather_info){
alert("test");
}
我知道这可能很简单,但我不知道我做错了什么如果有人能帮助我,我将非常感激。
你的代码中有相当多的语法错误,查看你的浏览器控制台以便跟踪这些错误(IE9和Chrome的F12, Firefox的Ctrl+Shift+J)。这段代码在我这端运行得很好:
document.getElementById("widget-container-1").innerHTML = "<div class='title'>Select town: "+
"<select id='drop'>"+
"<option name='Auckland' value='Auckland'>Auckland</option>"+
"<option name='Christchurch' value='Christchurch'>Christchurch</option>"+
"<option name='Dunedin' value='Dunedin'>Dunedin</option>"+
"<option>Hamilton</option>"+
"<option>Tauranga</option>"+
"<option>Wellington</option>"+
"</select><br />"+
"<button id='update' name='update' onClick='"_refreshWeatherDisplay('test');'">update</button></div>"+
"<div class='monitor'>Sort by"+
"<input id='radio' name='input' type='radio' value='0' >town"+
"<input id='radio' name='input' type='radio' value='1' >max temp"+
"<div class='section'>test</div></div>";
select = document.getElementById("drop");
select.onchange = function(){
_checkNewTown(select.options[select.selectedIndex].value);
};
和你的功能:
var _checkNewTown = function(ntown){
alert(ntown);
};
var _refreshWeatherDisplay = function(weather_info){
alert("test");
};
相关文章:
- 在ember/handlers中使用value和valueBinding有什么区别
- jquery if语句返回return wong语句
- 函数在return语句之前返回空对象
- Javascript Return and if/else
- 需要url导航从DropDown Value onClick按钮传递url变量
- Fizz Buzz return value javascript
- 为什么我需要写“;function(value){return my_function(value);作为node.js
- Return <td> value via onclick()
- How does jQuery's .not() return value affect .hide()?
- Javascript & jquery return value
- Jscript CRM Return Value
- document.getElementById().value return undefined in chrome
- return value from onClick
- Meteor.WrapAsync don't return value
- AngularJS http return value
- return object if list<object> value is exists (Javascr
- javascript innerhtml return value
- Java Script Return Value
- Sharepoint Online executeQueryAsync JSOM - Return Value
- 通过AJAX在JavaScript中生成一个变量return Value