简体   繁体   中英

How to call grab the value of a button inside the iframe using jquery?

I have 2 html pages ( a.html and b.html ). I have made an <iframe> and set b.html as a source of a.html. But how do I call at a.html to grab the value of b.html button using jquery via class name? FYI: Both are in the same domain. How can I achieve that?

a.html

<html>
<head>
    <title>a.html</title>
    <script>
        function howToGetValueOfBtn() {

        }
    </script>
</head>
<body>
    <iframe src="b.html"></iframe>
</body>
</html>

b.html

<html>
<body>
    <input type="button" value="getThisValue" class="btn"/>
</body>
</html>

Thanks for all the helps in advance!

Try this:

var button_value = $('iframe').contents().find('.btn').val();

But it would be best if you give your button an Id

var button_value = $('iframe').contents().find('#btn_Value').val(); 
<input type="button" value="getThisValue" class="btn" id="btn_Value"/>

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM