2017-05-26 121 views

回答

0

您可以使用模板文字,.insertAdjacentHTML()

var div = `<div kendo-grid id="tempGrid" hidden="hidden" k-options="meterGridOptions" k-rebind="columns">div</div>`; 
 

 
document.body.insertAdjacentHTML("beforeend", div);
<body></body>

0
var m=document.getElementById('d1'); 
m.setAttribute("style","height:50%"); 
+1

儘管此代碼可能會回答問題,但提供有關如何解決問題和/或爲何解決問題的其他上下文可以提高答案的長期價值。 –

0

您可以使用element.setAttributeNode(name, value)

var myDiv = document.createElement("div"); 
 
myDiv.setAttribute("kendo-grid", ""); 
 
myDiv.setAttribute("id", "tempGrid"); 
 
myDiv.setAttribute("hidden", "hidden"); 
 
myDiv.setAttribute("k-options", "meterGridOptions"); 
 
myDiv.setAttribute("k-rebind", "columns"); 
 

 
document.body.appendChild(myDiv)

0

我剛剛刪除了屬性hidden以便它可見。

$(document).ready(function() { 
 
    var div = $("<div/>", { 
 
    "id": "tempGrid", 
 
    "k-options": "meterGridOptions", 
 
    "k-rebind": "columns" 
 
    }).text("Created via Jquery"); 
 

 
    div.attr("kendo-grid", ""); 
 
    div.appendTo(".container"); 
 
});
.container { 
 
    background-color: green; 
 
    width: 100px; 
 
    height: 50px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 

 
<div class="container"> 
 

 
</div>