【问题标题】:how to fire an event on textbox value change from pop window in MVC ASP.net如何从 MVC ASP.net 中的弹出窗口中触发文本框值更改的事件
【发布时间】:2011-06-22 05:23:14
【问题描述】:

我现在从弹出窗口返回一个值,我想要的是文本框值从弹出窗口更改,它应该将其背景颜色更改为红色,否则不会反映任何更改。 我在做什么

<input  type="button" id="button1" value="button1" style="width:95%;font-family:Verdana;font-size:9px;" onclick="window.open( '<%= Url.Action( "PopUp", "Home"  ) %>' ,'popup','height=410','width=200','target=popup','center','front');" onfocus="if(document.getElementById('HiddenVal').value!=null||document.getElementById('HiddenVal').value!=''){txtbutton.value=document.getElementById('HiddenVal').value ; document.getElementById('HiddenVal').value='';}" />

其中 txtbutton 是文本框,而 button1 是打开弹出窗口的按钮。如果文本框的值改变了,我想改变它的颜色;否则它的背景应该是白色的。

【问题讨论】:

  • 如何从弹出窗口返回值?
  • 在 document.getElementById('HiddenVal').value 中,我正在获取值。
  • 您正在尝试更改按钮焦点上文本框的颜色?

标签: javascript jquery asp.net-mvc model-view-controller


【解决方案1】:

从按钮中删除您的 onfocus 代码,然后将此代码放入您的 js 文件中。

$('#button1').focus(function(){
   if(document.getElementById('HiddenVal').value!=null&&document.getElementById('HiddenVal').value!=''){
        $('#txtbutton', window.parent.document).css("background-color","red"); //Assuming txtbutton is ID of your textbox
         document.getElementById('HiddenVal').value='';
   }
} );

您可以尝试的另一种方法是在父窗口中编写一个函数,然后从子窗口调用该函数 - 类似这样 -

<script> 
function ifDoneChild(val) {   
 $('#txtbutton').css("background-color","red");
} 
</script> 

从子窗口调用这个函数-

 $('#button1').focus(function(){
           if(document.getElementById('HiddenVal').value!=null&&document.getElementById('HiddenVal').value!=''){
               window.parent.ifDoneChild(); 
            }
     });

【讨论】:

  • 很好。很高兴听到它对您有用。您可以对答案进行投票,并可以通过单击我的答案左侧的复选标记来选择答案。
猜你喜欢
  • 2022-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-20
相关资源
最近更新 更多