如何添加javascript img?

时间:2015-05-08 20:15:00

标签: javascript jquery

我知道对于一个javascript程序员来说这可能是非常容易的,但我想更改位于我的文件夹资产/ img / avatar / incorrect.png中的图像的“错误答案”和“正确答案”任何想法我怎么可能做这个?我试过谷歌,但我尝试过的每一个选项似乎都不起作用?

<script type="text/javascript">
    $( "#myForm" ).submit(function( event ) {
            event.preventDefault();
            if(!$("#myForm").validationEngine('validate'))
            {
                return false;
            }
            var id = $('input[type=radio][name=is_correct]:checked').attr('id');
            var formData = $("#myForm").serializeArray();
            $.ajax
                ({
                    type: "POST",
                    url: "<?php echo base_url()?>user/checkanswer/<?php echo $questionrecord[0]['id']?>/"+id,
                    cache: false,
                    data : formData,
                    async: false,
                    success: function(data)
                    {
                        if( data == '0' ){
                        $("#msgbox_answer").fadeTo(200,0.1,function() {  //start fading the messagebox

                            //add message and change the class of the box and start fading
                            $(this).html('Incorrect Answer').addClass('messageboxerror').fadeTo(900,1);
                              document["pic1"].src = "assets/img/avatars/incorrect.png";
                        });
                        }else if( data == '1' ){
                            $("#msgbox_answer").fadeTo(200,0.1,function() {  //start fading the messagebox

                                //add message and change the class of the box and start fading
                                $(this).html(' Correct Answer').addClass('messageboxok').fadeTo(900,1);
                            });
                        }
                        $( "#remove_submit" ).remove();
                        $("#view_correct_answer").html('<a href="javascript:void(0);" onclick="javascript:showDiv();"><span class="whitetext">View correct answer</span></a>');
                    }
                });
        });

        $(".hidetext").click(function () {
            $(".text_class").toggle("slow")
        });

        $('.carousel').carousel({
            interval: 4000 //changes the speed
        })
    </script>

0 个答案:

没有答案