ios*_*s85 5 html jquery drop-down-menu
在我的下拉列表中,我进行了设置,以便onchange应该调用checkval并传入元素的id.我刚刚开始使用真正基本的登录,但是甚至无法显示警报.我究竟做错了什么?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script>
function checkval(id){
if($('#' + id).val == "Other")
{
alert("You Selected Other");
//other logic will go here
}
}
</script>
</head>
<body>
<select name="items1[]" id="items1[]" onchange="checkval(id);">
<option selected value="">Select One</option>
<option value="one">One</option>
<option value="Other">Other</option>
</select>
<select name="items2[]" id="items2[]" onchange="checkval(id);">
<option selected value="">Select One</option>
<option value="one">One</option>
<option value="Other">Other</option>
</select>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
编辑:似乎 id items1[] 失败了。所以改变了你的标记位。在这里修复了jsFiddle。
请参阅链接,了解DOM ID 中允许使用哪些字符?
将您的标记更改为onchange="checkval(this.id);".
和脚本作为
function checkval(id){
if($('#' + id).val() == "Other")
{
alert("You Selected Other");
//other logic will go here
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5261 次 |
| 最近记录: |