gpt4 book ai didi

jquery - 页面加载时检查预选选项值

转载 作者:行者123 更新时间:2023-12-01 06:29:31 25 4
gpt4 key购买 nike

当页面加载时,我动态地将选项设置为某个值。我如何在页面加载时检查该值,然后更改另一个 div 内容?我最好的猜测如下,但我没有运气。

$("select[name=mySelections]").onload.function() {
if ($(this).find("option:selected").val() == 'myvalue') {
$("#myDiv").html("Test");
}
}

我的选择器

{html_options name="mySelections" options=$myOptions selected=$test->One}

我的html

<div id="myDiv"
{foreach from $whatever to $this}
<input type="checkbox" name="{$this->Name}" value="{$this->value}" />
{/foreach
</div>

最佳答案

看起来您正在尝试检查 HTML select 元素是否已加载,但您应该检查 DOM 是否已加载,如下所示:

$(document).ready(function() {
if ($("select[name=mySelections] option:selected").val() == 'myvalue') {
$("#myDiv").html("Test");
}
});

关于jquery - 页面加载时检查预选选项值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8763565/

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