[英]Modifying innerHTML from 3rd Party Script
我有第三方腳本導入菜單,我無法編輯此第三方腳本。 它會生成如下代碼:
<div id="wmenu-updated" style="display: block;">
<small>Menu updated</small>
<span innerhtml="19 hours ago"></span>
</div>
它應該需要19 hours ago
並在跨度中顯示為文本,但無論出於何種原因它都不起作用,腳本的制作者在修復錯誤方面沒什么幫助。
有沒有辦法,使用jQuery,一旦頁面加載我可以采取innerhtml
並將其吐出作為該跨度內的文本?
$( document ).ready( function () {
$( '#wmenu-updated span' ).text( function () {
return $( this ).attr( 'innerhtml' );
});
});
您可以使用jQuery的文本函數來更新范圍中的文本
你可以嘗試這個: 小提琴
$(function(){
$(document).children('#wmenu-updated').find('span[innerhtml]')
.text($(this).attr("innerhtml"));
});
或者更簡單:
$('span[innerhtml]').text($('span[innerhtml]').attr('innerhtml'));
嘗試這個:
$(document).ready( function ( e ) {
var q = $('span').attr('innerhtml');
$('#wmenu-updated').children('span').text( q );
});
很多人都很接近:)
這將為您做到:
$('selector').find('span[innerhtml]').each(function() {
$(this).html($(this).attr('innerhtml'));
});
這在功能上是等價的:
$('selector').find('span[innerhtml]').html(function() {
return $(this).attr('innerhtml');
});
$("#wmenu span").attr("innerhtml", "Your Update here");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.