Alert 从javascript中的下拉函数读取变量
我正在html文件中使用此下拉列表:Alert 从javascript中的下拉函数读取变量,alert,dropdown,Alert,Dropdown,我正在html文件中使用此下拉列表: <select id="read-type" onchange="checkrt()"> <option value="1">2word</option> <option value="2">3word</option>
<select id="read-type" onchange="checkrt()">
<option value="1">2word</option>
<option value="2">3word</option>
<option value="3">line</option>
</select>
</div>
但此代码无法读取“onchange”或我现在不知道如何读取,因此我将代码更改为:
$(function checkrt(){
$('#read-type').on('change', function(){
window.readtype = $(this).val();
alert(readtype);
});
})
最后一段代码对“alert”很有效,但我无法通过以下方式读取下一个函数中的变量“readtype”:
Function delta(text){
if (readtype == 1)
这给我消息(un define readtype)?,请回答问题
注意:如果我在下拉列表中更改所选项目后单击浏览器中的“刷新”按钮,则代码可能会获得readtype
- app.js中的代码不是html
- 不需要命名函数来包含
onchange
触发器。要访问该值,必须将readtype
传递到下一个函数中
将代码更改为:
$(函数(){
$('#读取类型')。在('change',function(){
var readtype=$(this.val();
nextFunction(readtype);
});
函数nextFunction(readtype){
if(readtype==1){
警报(readtype);
}
}
});代码>
2字
3字
线
谢谢,但我的第二个功能是第一个功能中的第二个,很抱歉不能与我一起使用。
Function delta(text){
if (readtype == 1)