如何获得outerHTML与jquery为了让它跨浏览器 [英] how to get outerHTML with jquery in order to have it cross-browser

查看:330
本文介绍了如何获得outerHTML与jquery为了让它跨浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个jQuery论坛中发现了一个响应,他们做了一个函数来做到这一点,但结果是不一样的。
下面是一个为图像按钮创建的示例:

I found a response in a jquery forum and they made a function to do this but the result is not the same. Here is an example that I created for an image button:

var buttonField = $('<input type="image" />');
    buttonField.attr('id', 'butonFshi' + lastsel);
    buttonField.val('Fshi');
    buttonField.attr('src', 'images/square-icon.png');
    if (disabled)
        buttonField.attr("disabled", "disabled");
    buttonField.val('Fshi');
    if (onblur !== undefined)
        buttonField.focusout(function () { onblur(); });
    buttonField.mouseover(function () { ndryshoImazhin(1, lastsel.toString()); });
    buttonField.mouseout(function () { ndryshoImazhin(0, lastsel.toString()); });
    buttonField.click(function () { fshiClicked(lastsel.toString()); });

我有这种情况:

 buttonField[0].outerHTML = `<INPUT id=butonFshi1 value=Fshi src="images/square-icon.png" type=image jQuery15205073038169030395="44">`

而我找到的外部函数给出了buttonField.outer()= < INPUT id = butonFshi1 value = Fshi src =images / square-icon.pngtype = image>

instead the outer function I found gives buttonField.outer() = <INPUT id=butonFshi1 value=Fshi src="images/square-icon.png" type=image>

函数是:

$.fn.outer = function(val){
    if(val){
        $(val).insertBefore(this);
        $(this).remove();
    }
    else{ return $("<div>").append($(this).clone()).html(); }
}

所以像这样我松开了我插入的处理程序。
无论如何,为了让浏览器在不丢失处理程序的情况下使用jquery获得outerHTML?

so like this I loose the handlers that I inserted. Is there anyway to get the outerHTML with jquery in order to have it cross-browser without loosing the handlers ?!

推荐答案

p>尝试这个:

var html_text = `<INPUT id=butonFshi1 value=Fshi src="images/square-icon.png" type=image jQuery15205073038169030395="44">`
buttonField[0].html(html_text);

:)

这篇关于如何获得outerHTML与jquery为了让它跨浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆