javascript - innerHTML in bootstrap modal - Stack Overflow

I am now spending hours on one thing.innerHTML changes div or javascript code:function myFunction() {d

I am now spending hours on one thing. innerHTML changes div or

javascript code:

function myFunction() {
    document.getElementById("demo").innerHTML = "Hello World";
}

Modal:

<!-- Template -->
<div id="faqask" class="modal fade" tabindex="-1" role="dialog" style="display: none;">
    <div class="modal-dialog modal-lg" style="margin-top:20%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">Uzdot Jautājumu</h4>
            </div>
            <div class="modal-body">
                <p id="demo" >trlololo</p>
                <button onclick="myFunction()">Click me</button>
                <select name="faqcategory" id='inputSelect' class="form-control form-group-margin input-lg">
                    <option value="" disabled selected>-Izvēlies-</option>
                    <option value="visparigie" />Vispārīgie
                    <option value="serveris"/>Serveris
                    <option value="pakalpojumi"/>Pakalpojumi
                </select>
                <textarea placeholder="Tavs Jautājums" class="form-control form-group-margin input-lg" rows="6"></textarea>
                <div class="clearfix"><button class="btn btn-lg btn-block btn-flat btn-primary" onclick="faqsend()">Iesūtīt jautājumu</button></div>
            </div>
        </div><!-- / .modal-content -->
    </div><!-- / .modal-dialog -->

</div>
<!-- / Template -->

I tested, if i put trlololo

outside of MODAL trololo change to Hello World, if i put it inside nothing happens.

But I really want it to work, because i want to send error to modal, so when button is pressed user get results to MODAL. But can`t get it to change. Outside it dose.

I am now spending hours on one thing. innerHTML changes div or

javascript code:

function myFunction() {
    document.getElementById("demo").innerHTML = "Hello World";
}

Modal:

<!-- Template -->
<div id="faqask" class="modal fade" tabindex="-1" role="dialog" style="display: none;">
    <div class="modal-dialog modal-lg" style="margin-top:20%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">Uzdot Jautājumu</h4>
            </div>
            <div class="modal-body">
                <p id="demo" >trlololo</p>
                <button onclick="myFunction()">Click me</button>
                <select name="faqcategory" id='inputSelect' class="form-control form-group-margin input-lg">
                    <option value="" disabled selected>-Izvēlies-</option>
                    <option value="visparigie" />Vispārīgie
                    <option value="serveris"/>Serveris
                    <option value="pakalpojumi"/>Pakalpojumi
                </select>
                <textarea placeholder="Tavs Jautājums" class="form-control form-group-margin input-lg" rows="6"></textarea>
                <div class="clearfix"><button class="btn btn-lg btn-block btn-flat btn-primary" onclick="faqsend()">Iesūtīt jautājumu</button></div>
            </div>
        </div><!-- / .modal-content -->
    </div><!-- / .modal-dialog -->

</div>
<!-- / Template -->

I tested, if i put trlololo

outside of MODAL trololo change to Hello World, if i put it inside nothing happens.

But I really want it to work, because i want to send error to modal, so when button is pressed user get results to MODAL. But can`t get it to change. Outside it dose.

Share Improve this question edited Sep 9, 2015 at 14:12 Ɛɔıs3 7,89911 gold badges53 silver badges83 bronze badges asked Sep 9, 2015 at 14:02 user3241944user3241944 251 silver badge7 bronze badges 2
  • "inside" mean where exactly ? – Nilesh Mistry Commented Sep 9, 2015 at 14:23
  • Bootstrap Modal, the modal code. If the <p id="demo" >trlololo</p> is anywhere outside modal code that i gave, it changes to Hello World. But if it`s inside modal code, nothing happens. – user3241944 Commented Sep 9, 2015 at 14:26
Add a ment  | 

1 Answer 1

Reset to default 3

Your code seems to work on jsfiddle. However, I had to change when the javascript runs to inside the body, likely after the page has loaded. You can, however, switch to jQuery since Bootstrap requires it to handle your clicking of the button for you.

$('#yourButtonID').click(function() {

  $('#demo').html('Hello World!');

});

JSFiddle

I added a button to show the modal.

If you don't want to change your code then I would suggest adding myFunction() to the end of the page just before the end of the <body> tag.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745186531a4615663.html

相关推荐

  • javascript - innerHTML in bootstrap modal - Stack Overflow

    I am now spending hours on one thing.innerHTML changes div or javascript code:function myFunction() {d

    9小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信