gpt4 book ai didi

javascript - 设置表单默认参数

转载 作者:行者123 更新时间:2023-11-27 23:27:50 26 4
gpt4 key购买 nike

@{  List<System.Web.Mvc.SelectListItem> Month = new List<System.Web.Mvc.SelectListItem>();

}
<script type="text/javascript">


function setImage(param) {
document.getElementById('ReportParameter').value = param;
// alert(document.getElementById('ReportParameter').value);
}

</script>

<form id="reportParametersForm" method="GET" action="@string.Format("{0}/{1}", @Url.Content("~/Reports/View"), ViewBag.Report)">
<fieldset style="padding: 0.2em 0 1.2em 0; height: 50px">
<legend style="margin: 0 1px 0 10px; padding: 3px 36px 3px 20px; background-color: #494949;
color: white; font-size: 11pt;">
@Html.Resource(String.Format("Report_{0}", ViewBag.Report as string))</legend>
<table border="0" cellspacing="0" cellpadding="0" style="font-size: x-small">
<input type="hidden" name="ReportParameter" id="ReportParameter" value=""/>
</table>
<div align="center">
<button class="button" id="Day" style="width:90px; height:46px" type="submit" onclick="setImage('1') ;">
Day</button>

<button class="button" id="Week" style="width:90px; height:46px" type="submit" onclick="setImage('2') ;">
Week</button>

<button class="button" id="Month" style="width:90px; height:46px" type="submit" onclick="setImage('3') ;">
Month</button>

</div>
<input type="hidden" name="ShowToolBar" value="false" />

</fieldset>
</form>
<script type="text/javascript">
var links = $('button');

links.click(function () {
links.css('background-color', '#2B2B2B');
$(this).css('background-color', '#BE4856');
});
</script>

当我打开有 3 个不同按钮的页面时,当我选择某个按钮时,我会看到不同的图像,如何将图像 1 设置为默认选择?我希望在屏幕上看到图像 1,并且默认选择按钮 1,但是当我选择按钮 1,2,3 时也能够看到其他图像

最佳答案

创建函数setDefaults(),并在启动时调用它为了使代码更清晰,您可以将html中相关图像的数据属性传递给每个按钮。

         <button class="button" id="Day" style="width:90px; height:46px" type="submit" data-image="1">
Day</button>

<button class="button" id="Week" style="width:90px; height:46px" type="submit" data-image="2">
Week</button>

<button class="button" id="Month" style="width:90px; height:46px" type="submit" data-image="3">
Month</button>

还有辅助函数 setActiveButton() 可以更改样式。

function setDefaults(buttonId) {
var button = $('#' + buttonId);
setActiveButton(buttonId);
setImage(button.data('image'));
}

function setActiveButton(buttonId) {
var links = $('button');
links.css('background-color', '#2B2B2B');
$('#' + buttonId).css('background-color', '#BE4856');
}

在你的脚本标签内

<script type="text/javascript">
var links = $('button');

links.click(function () {
setActiveButton(this.id);

});
setDefaults('Day');
</script>

关于javascript - 设置表单默认参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34809587/

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