gpt4 book ai didi

javascript - 如何根据下拉选择自动点击超链接?

转载 作者:行者123 更新时间:2023-11-30 19:38:51 25 4
gpt4 key购买 nike

当我在下拉列表中选择特定选项时,我希望点击特定链接

我试过了

$('#OTST').change(function () {
if ($('#OTST').val() == "2")
{
$("#STSelectedPhase0").trigger('click');
}
else if ($('#OTST').val() == "3")
{
$("#OTSelectedPhase0").trigger('click');
}
else
{
$("#AllSelectedPhase0").trigger('click');
}
});

也试过

 $("#AllSelectedPhase0").click();

但这些都不起作用

这是我的链接代码

@Html.EncodedActionLink("All", "TimeReportingDetails", "TimeReporting", new { companyId = Tlitem.CompanyId, companyWeekEnding = Tlitem.WeekEnding, FileId = Tlitem.FileId, jobId = Tlitem.JobId, jobType = Tlitem.JobType, phaseno = 0, OTST = "" }, new { Id = "AllSelectedPhase0" });

@Html.EncodedActionLink("ST", "TimeReportingDetails", "TimeReporting", new { companyId = Tlitem.CompanyId, companyWeekEnding = Tlitem.WeekEnding, FileId = Tlitem.FileId, jobId = Tlitem.JobId, jobType = Tlitem.JobType, phaseno = 0, OTST = 2 }, new { Id = "STSelectedPhase0" });

@Html.EncodedActionLink("OT", "TimeReportingDetails", "TimeReporting", new { companyId = Tlitem.CompanyId, companyWeekEnding = Tlitem.WeekEnding, FileId = Tlitem.FileId, jobId = Tlitem.JobId, jobType = Tlitem.JobType, phaseno = 0, OTST = 3 }, new { Id = "OTSelectedPhase0" });

下拉菜单的代码是:

  <select id = "OTST"  class = "form-control js-select " name="OTST"  >
<option value="0" selected="selected">All</option>
<option value="2">ST</option>
<option value="3">OT</option>
</select>

最佳答案

这是您触发事件点击的问题,但实际上它返回了您的元素。当你看到 $("#STSelectedPhase0").trigger('click')$("#STSelectedPhase0").click() 都返回你的元素 `.

对于自动点击超链接,您应该使用 $("#STSelectedPhase0")[0].click()

$("#btngoogle").click(function(){
$("#alink")[0].click()
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a id="alink" href="https://www.google.com">Test</a>
<input id="btngoogle" type="button" value="Google">
我已将代码放在按钮点击触发器 href 上。

如果需要更多信息,请告诉我。 :)

关于javascript - 如何根据下拉选择自动点击超链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55629246/

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