gpt4 book ai didi

Javascript自动选择下拉菜单调试错误

转载 作者:行者123 更新时间:2023-12-03 03:53:57 25 4
gpt4 key购买 nike

我遇到一个问题,在 Chrome Javascript 控制台中运行以下代码会引发以下错误:无法读取未定义的属性“ready”

我没有正确实例化该函数吗?我很困惑我做错了什么。

$(document).ready(function(){
setTimeout(function() {
$('select[name="ctl00$ContentPlaceHolder1$DropDownListSources"]').first().val("Plant/Unit Seed File");
}, 1000)
setTimeout(function() {
$('select[name="ctl00$ContentPlaceHolder1$DropDownListEquipmentTypes"]').first().val("Plant");
}, 4000)
document.getElementById('ctl00_ContentPlaceHolder1_ButtonImportNow').click();
})

最佳答案

正如我在评论中所说,您需要引用 jquery 才能使用该库。除非您停在带有 jquery 引用的页面上的断点处,否则浏览器的控制台将无法使用 jquery 或任何其他外部提供的功能图书馆。

如果您查看下面的代码片段,您会发现有一个 jquery 脚本标记。仍然会引发 JavaScript 错误,但由于 jquery 引用,不再引发错误 Cannot read property 'ready' of undefined

$(document).ready(function(){
setTimeout(function() {
$('select[name="ctl00$ContentPlaceHolder1$DropDownListSources"]').first().val("Plant/Unit Seed File");
}, 1000)
setTimeout(function() {
$('select[name="ctl00$ContentPlaceHolder1$DropDownListEquipmentTypes"]').first().val("Plant");
}, 4000)
document.getElementById('ctl00_ContentPlaceHolder1_ButtonImportNow').click();
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

关于Javascript自动选择下拉菜单调试错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45038246/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com