简体   繁体   English

在变量中使用$(document).ready和html

[英]Using $(document).ready with a html inside a variable

Can i use jquery function $(document).ready(function() {}); 我可以使用jquery 函数$(document).ready(function(){}); using a javascript variable containing html recovered from a $("#tableId").prop("outerHTML"); 使用包含从$(“#tableId”)。prop(“ outerHTML”)中恢复的html的javascript变量 function as parameter? 作为参数? Just like down bellow: 就像下面这样:

$(document).ready(function() {
var tempHtml = $("#tabelaOriginal-1").prop("outerHTML");
$(tempHtml).ready(function() {
    $("someDivId").css( "background-color", "yellow" );
});

The tempHtml will suffer changes? tempHtml是否会发生变化? Caused by the .css function call. 由.css函数调用引起。 In short, i need recover html data from a div and do some alterations and build a modal with this alterations without make any alterations in the original div. 简而言之,我需要从div恢复html数据并进行一些更改,并使用此更改构建模式,而无需在原始div中进行任何更改。 So i'm trying to use the inner call of jquery .ready function passing the outerHTML as parameter. 所以我试图使用jquery .ready函数的内部调用,将externalHTML作为参数传递。

You can use jQuery's clone method for what you are trying to achieve. 您可以使用jQuery的clone方法来实现您想要的目标。

$(document).ready(function() {
   var clone = $("#tabelaOriginal-1").clone();
   clone.css( "background-color", "yellow" );
   //Now use the cloned object in a modal or do whatever you want.
});

I strongly recommend you to go through clone documentation to understand it's optional features. 我强烈建议您仔细阅读clone文档以了解它的可选功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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