从iframe访问父页面的id元素(accessing id element of parent page from iframe)
如何从iframe访问id元素到父页面? 我试图使用这种方法,但仍然无法正常工作。
Parent.html
<html> <head> <title>Parent</title> </head> <body> <button id="click" onclick="alert('Hello');">click</button> <iframe id="iframe1" src="iframe.html"> </iframe> </body> </html>
Iframe.html的
<!DOCTYPE html> <html> <head> <title>Parent</title> <script type="text/javascript" src="http://code.jquery.com/jquery-3.1.0.slim.js"></script> <script> $(function() { var money = 20000; $("#nominal").on("change keyup", function() { var input = $(this); // remove possible existing message if( input.next().is("form") ) input.next().remove(); // show message if( input.val() > money ) window.parent.$('#click').trigger('click'); }); }); </script> </head> <body> <input type="text" id="nominal"> </body> </html>
我创建的脚本是否有问题? 请帮我改进这段代码。 提前致谢。
问题解决了
How can I access id element from iframe to parent page? I have tried to use this method but still not work.
Parent.html
<html> <head> <title>Parent</title> </head> <body> <button id="click" onclick="alert('Hello');">click</button> <iframe id="iframe1" src="iframe.html"> </iframe> </body> </html>
iframe.html
<!DOCTYPE html> <html> <head> <title>Parent</title> <script type="text/javascript" src="http://code.jquery.com/jquery-3.1.0.slim.js"></script> <script> $(function() { var money = 20000; $("#nominal").on("change keyup", function() { var input = $(this); // remove possible existing message if( input.next().is("form") ) input.next().remove(); // show message if( input.val() > money ) window.parent.$('#click').trigger('click'); }); }); </script> </head> <body> <input type="text" id="nominal"> </body> </html>
Whether there is something wrong with the script I created? Please help me to improve this code. Thanks in advance.
PROBLEM SOLVED
原文:https://stackoverflow.com/questions/38517879
满意答案
好的,我是如何解决它的,感谢所有回复,我正在寻找一种方法将事件附加到在运行时(初始化之后)动态创建的按钮。 希望它也适用于其他人。
<script type="text/javascript"> function ButtonClick(buttonId) { alert("Button " + buttonId + " clicked from javascript"); } </script> protected void Button_Click(object sender, EventArgs e) { ClientScript.RegisterClientScriptBlock(this.GetType(), ((Button)sender).ID, "<script>alert('Button_Click');</script>"); Response.Write(DateTime.Now.ToString() + ": " + ((Button)sender).ID + " was clicked"); } private Button GetButton(string id, string name) { Button b = new Button(); b.Text = name; b.ID = id; b.Click += new EventHandler(Button_Click); b.OnClientClick = "ButtonClick('" + b.ClientID + "')"; return b; }
Ok here is how I solved it, Thanks for all replies, I was looking for a way to attach an event to a button that is created dynamically during runtime (after initialization). Hope It works for others as well.
<script type="text/javascript"> function ButtonClick(buttonId) { alert("Button " + buttonId + " clicked from javascript"); } </script> protected void Button_Click(object sender, EventArgs e) { ClientScript.RegisterClientScriptBlock(this.GetType(), ((Button)sender).ID, "<script>alert('Button_Click');</script>"); Response.Write(DateTime.Now.ToString() + ": " + ((Button)sender).ID + " was clicked"); } private Button GetButton(string id, string name) { Button b = new Button(); b.Text = name; b.ID = id; b.Click += new EventHandler(Button_Click); b.OnClientClick = "ButtonClick('" + b.ClientID + "')"; return b; }
相关问答
更多jQuery - 动态创建按钮并附加事件处理程序(jQuery - Dynamically Create Button and Attach Event Handler)
SharePoint:CompositeField在预渲染事件期间抛出NullReferenceException(SharePoint:CompositeField throws NullReferenceException during pre-render event)
以编程方式在SharePoint中创建asp:Button和attach事件(Programmatically create asp:Button and attach event in SharePoint)
Sharepoint WebPart(Sharepoint WebPart)
事件接收器sharepoint在线(event receiver sharepoint online)
在sharepoint中重复事件(Repeating event in sharepoint)
ASP.NET以编程方式添加带事件的按钮(ASP.NET Programmatically adding button with an event)
SharePoint安全编程问题(SharePoint security programming issue)
SharePoint 2010:创建“提醒我”按钮(SharePoint 2010: Create “Alert Me” button)
asp.net onclick事件没有被解雇(asp.net onclick event not fired)
相关文章
更多如何向一个页面中的两个iframe传值
如何获取iframe刷新后的内容
div 与 iframe页面缩小问题 [JavaScript]
js 通过td的id值 如何拿到tr的id值?
Stack Overflow Architecture Update - Now At 95 Million Page Views A Month
使用TabPanel时,如果两个页面存在相同的id。
MongoDB _id和ObjectId详解
solr required field: id
The content of element type "package" must match "...
html中一个div的id是“1:222”的话,怎么利用id给它定义css啊?
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!