admin管理员组文章数量:1404927
I'm new to HTML and javascript. When I try to initiate a popup window, I find the usual way to do is like this:
var popup = new Popup(title, content);
where content
is string of html containing the content of the popup box, such as
var content = "<div> \
<input type='text'> \
</div> "
This writing style is really ugly, and when the content gets plex, the code is hardly readable. What's the good practice for doing this?
Edit By popup I didn't mean a new browser window, but something like when you click on a pin on Google map, detailed information about that pip will pop up.
I'm new to HTML and javascript. When I try to initiate a popup window, I find the usual way to do is like this:
var popup = new Popup(title, content);
where content
is string of html containing the content of the popup box, such as
var content = "<div> \
<input type='text'> \
</div> "
This writing style is really ugly, and when the content gets plex, the code is hardly readable. What's the good practice for doing this?
Edit By popup I didn't mean a new browser window, but something like when you click on a pin on Google map, detailed information about that pip will pop up.
Share Improve this question edited Aug 30, 2020 at 21:25 HoldOffHunger 21k11 gold badges120 silver badges146 bronze badges asked May 10, 2013 at 14:42 DongDong 3323 silver badges10 bronze badges 1- You could have the popup content on the html page and just toggle showing or hiding it, or just copy it directly – Explosion Pills Commented May 10, 2013 at 14:46
2 Answers
Reset to default 5I'd suggest using a hidden div with the text you want to display and then reading it and putting into Popup
- something like
<div id="myPopup" style="display: none;">Popup content</div>
<script>
var x=document.getElementById("myPopup");
var p = new Popup(title, x.innerHTML);
</script>
It will be best to open an html page as a popup. Please take a look at http://www.quirksmode/js/popup.html and http://www.yourhtmlsource./javascript/popupwindows.html
This case you can add some inputs, or other html elements inside the popup and even implement logic in the popup page.
本文标签: javascriptWhat39s the good practice to add html content of popup box in JS codeStack Overflow
版权声明:本文标题:javascript - What's the good practice to add html content of popup box in JS code? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744866364a2629367.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论