我在使用jquery $( type=text ).resize(){}更新输入窗口或文本框控件文本值时遇到了问题;我知道该事件之所以会触发,是因为当我调整浏览器大小时会出现一个警告。我也在用这个功能做其他的事情。
它目前看起来是这样的:
$(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" />
总而言之,我一直在寻找一种随着页面大小调整页面大小而动态更新值的方法。我的问题是,我没有使用正确的东西来识别身份。感谢您花时间查看这篇文章,并感谢您的回复。
另外,我也对使用javascript函数的想法持开放态度,但我似乎甚至不能让函数为resize事件触发,所以它需要更多的帮助。这就是我到目前为止所知道的:
window.onresize=Test();
function Test(){
var hdnfld= document.getElementById("texttest");
var testing = window.innerWidth;
alert(testing);
hdnfld.text= testing;
}
发布于 2013-12-17 04:15:52
只使用不带点的元素的ID (它实际上表示您没有的类)。
所以请使用
$('#hiddentest').val(innerheight)
和
$('#texttest').val(innerheight)
请注意,asp:TextBox
呈现为inptut type="text"
,因此您仍然必须在其上使用.val()
,而不是.text()
发布于 2013-12-17 04:16:00
隐藏文本框id为"hiddentest“,因此代码将为
$('#hiddentest').val(innerheight);
发布于 2013-12-17 04:16:06
在您的情况下,hiddentest
是id
而不是class
试一下,
$(window).resize(function(){
if($(window).height()>500){
var innerheight = $(window).height();
$('#hiddentest').val(innerheight);
}
});
https://stackoverflow.com/questions/20619989
复制相似问题