Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我无法对jquery中的select字段执行任何操作_Jquery_Html_Dom - Fatal编程技术网

我无法对jquery中的select字段执行任何操作

我无法对jquery中的select字段执行任何操作,jquery,html,dom,Jquery,Html,Dom,这是代码。我无法在我的选择上看到任何更改。此处既不显示append,也不显示empty <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click

这是代码。我无法在我的选择上看到任何更改。此处既不显示append,也不显示empty

<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
    $(document).ready(function(){
        $("button").click(function(){
            alert("Button click");
            $("#myselect").empty();
            alert("Done");
            $("#myselect").append('<option value="3">3</option>');
        });
   };
</script>
</head>
<body>

<p id="intro">Hello World!</p>
<select id="myselect">
    <option value="1">1</option>
    <option value="2">2</option>
</select>
<button>Empty the Selector</button>
</body>
</html>

$(文档).ready(函数(){
$(“按钮”)。单击(函数(){
警报(“按钮点击”);
$(“#myselect”).empty();
警惕(“完成”);
$(“#myselect”).append('3');
});
};

你好,世界

1. 2. 清空选择器
您需要包含jQuery以使其正常工作。此外,您缺少关闭DOM就绪处理程序的

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("#myselect").empty();
        alert("Done");
        $("#myselect").append('<option value="3">3</option>');
    });
}); // <-- here
</script>

$(文档).ready(函数(){
$(“按钮”)。单击(函数(){
$(“#myselect”).empty();
警惕(“完成”);
$(“#myselect”).append('3');
});

}); // 您需要包含jQuery才能使其正常工作。另外,您缺少关闭DOM就绪处理程序的

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("#myselect").empty();
        alert("Done");
        $("#myselect").append('<option value="3">3</option>');
    });
}); // <-- here
</script>

$(文档).ready(函数(){
$(“按钮”)。单击(函数(){
$(“#myselect”).empty();
警惕(“完成”);
$(“#myselect”).append('3');
});

}); // 谢谢我意识到我已经更新了旧代码。你能看一下更新的脚本并告诉我你的意见吗。我很抱歉。这样一个小错误。非常感谢。我意识到我已经更新了旧代码。你能看一下更新的脚本并告诉我你的意见吗。我很抱歉。这样一个小错误。非常感谢你。