Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何添加javascript img?_Javascript_Jquery - Fatal编程技术网

如何添加javascript img?

如何添加javascript img?,javascript,jquery,Javascript,Jquery,我知道这对于javascript程序员来说可能非常容易,但我想更改位于我文件夹assets/img/avatar/incorrect.png中的图像的“错误答案”和“正确答案”,知道我该怎么做吗?我尝试过谷歌,但我尝试过的每一个选项似乎都不起作用 <script type="text/javascript"> $( "#myForm" ).submit(function( event ) { event.preventDefault();

我知道这对于javascript程序员来说可能非常容易,但我想更改位于我文件夹assets/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>

$(“#myForm”).submit(函数(事件){
event.preventDefault();
if(!$(“#myForm”).validationEngine('validate'))
{
返回false;
}
var id=$('input[type=radio][name=is_correct]:checked').attr('id');
var formData=$(“#myForm”).serializeArray();
$.ajax
({
类型:“POST”,
url:“用户/检查答案/”+id,
cache:false,
数据:formData,
async:false,
成功:功能(数据)
{
如果(数据='0'){
$(“#msgbox_answer”).fadeTo(200,0.1,function(){//开始淡入messagebox
//添加消息并更改框的类别,然后开始淡入淡出
$(this.html('error Answer').addClass('messageboxerror').fadeTo(900,1);
document[“pic1”].src=“assets/img/avatars/error.png”;
});
}else if(数据='1'){
$(“#msgbox_answer”).fadeTo(200,0.1,function(){//开始淡入messagebox
//添加消息并更改框的类别,然后开始淡入淡出
$(this.html('Correct Answer').addClass('messageboxok').fadeTo(900,1);
});
}
$(“#删除_提交”).remove();
$(“#查看(正确)答案”).html(“”);
}
});
});
$(“.hidetext”)。单击(函数(){
$(“.text\u class”)。切换(“慢速”)
});
$('.carousel')。carousel({
间隔:4000//更改速度
})

只需使用图像元素替换文本,将
错误答案更改为
只需在
messageboxerror
messageboxok
类中添加适当的背景图像即可。@APAD1谢谢!这奏效了:)@MichaelRodd干得好