gpt4 book ai didi

javascript - 如何多次调用函数?

转载 作者:行者123 更新时间:2023-12-02 17:11:21 25 4
gpt4 key购买 nike

我正在尝试实现调用函数的代码

<body>
<nav id="menu">
<div id="app">
<ul class="List">
<li><span>Enter Number below</span></li>
<div id="coachid">
<input type="text" name="coachid" id="textbox1" value="22984">
</div>
<li><span>Fitness Programs</span>
<ul id="programs">
<li class="Label">&nbsp;</li>
<li><span>10-Minute Trainer</span>
<ul id="10min">
<li class="Label">&nbsp;</li>
<li><span>Base</span>
<ul id="10minBase">
<li class="Label">&nbsp;</li>
<label for="basic">Text Input:</label>
<input type="hidden" name="basic" id="basic" value="10MinTrainer"/>
<button id="getWebSite">Open Website</button><br/>
</ul>
</li>
<li><span>Deluxe</span>
<ul id="10min">
<li class="Label">&nbsp;</li>
<input type="hidden" name="basic1" id="basic1" value="TMT"/>
<button id="getWebSite">Open Website</button><br/>
</ul>
</li>
<li><span>Deluxe</span>
<ul id="Deluxe">
<li class="Label">&nbsp;</li><input type="hidden" name="basic3" id="basic3" value="TMTUpgrade"/>
<button id="getWebSite">Open Website</button><br/>
<ul>
</li>
</ul>
</li>
</li>
<ul>
</li>
</ul>
</div>
</nav>
</body>

这是函数

$(function() {              
$('#getWebSite').unbind().click(function(){
goUrl = 'http://www.example.com/' + $("#basic").val() + '?referringRepId=' + $("#textbox1").val();
window.location = goUrl;
});
});

我试图在整个代码中多次调用该函数,以根据 html 中保存的信息将按钮重定向到某个站点。这可能吗?

最佳答案

您需要命名您的函数,将类应用于那些应具有点击处理程序的元素,并创建点击函数:

<button class="myClass">

$(function () {
function doSomething() {
goUrl = 'http://www.example.com/'
+ $("#basic").val()
+ '?referringRepId='
+ $("#textbox1").val();

window.location = goUrl;
}

$('.myClass').unbind().click(function () {
doSomething();
});
});

关于javascript - 如何多次调用函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24788211/

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