我在使用 jquery $(window).resize(function(){}); 更新输入 type=text 的值或 texbox 控件文本值时遇到问题我知道该事件会触发,因为当我调整浏览器大小时会出现警报。我还将该功能用于其他用途。
目前看起来像这样:
$(window).resize(function(){
if($(window).width()>1080){
var innerwidth = $(window).width()-170;
$("#div1").width(innerwidth);
}
我想添加这个:
$(window).resize(function(){
if($(window).height()>500){
var innerheight = $(window).height();
$('input.hiddentest').val(innerheight);
}
我知道问题出在:
$('input.hiddentest').val(innerheight);
我也尝试过这个:
$('#texttest.ClientID').text(innerheight);
这是我正在使用的输入和下面的文本框(请注意,该类型过去是隐藏的,但我认为这不会产生问题,我希望它出于调试目的可见)
<input id="hiddentest" type="text" visible="true" name="hiddentest" onclick="test();" runat="server" value="1000" />
<asp:TextBox id="texttest" Visible="true" runat="server" Text="1000" />
总的来说,我一直在寻找一种在页面大小随页面大小调整时动态更新值的方法。我的天哪,我没有使用正确的东西来识别 id。感谢您花时间查看此内容并做出任何回复。
附注我也愿意接受使用 javascript 函数的想法,但我什至似乎无法让该函数触发调整大小事件,因此它需要更多帮助。 这是我到目前为止所拥有的:
window.onresize=Test();
function Test(){
var hdnfld= document.getElementById("texttest");
var testing = window.innerWidth;
alert(testing);
hdnfld.text= testing;
}
最佳答案
仅使用不带点的元素 ID(实际上代表您没有的类)。
所以使用
$('#hiddentest').val(innerheight)
和
$('#texttest').val(innerheight)
请注意,asp:TextBox
呈现为 inptut type="text"
,因此您仍然必须对其使用 .val()
,不是 .text()
关于c# - 更新输入类型=文本值或文本框控件调整大小事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20619989/