0
我试图从iframe中删除width
和height
属性,并从我的输入中删除所有换行符。所以我做了这个:替换方法不起作用
var convert;
$(".button1").click(function(){
console.log("done");
var convert = document.getElementById("convert").value;
convert = convert.replace(/\r?\n/g, '');
//convert = convert.replace("width=\'500\' height=\'294\'")
convert= convert.replace("width=", '');
convert = convert.replace("height=", '');
convert= convert.replace("'500'", '');
convert= convert.replace("'294'", '');
console.log(convert);
})
但它有不一致的结果。有时它有效,有时不起作用。
我也尝试过注释掉的部分,但那也行不通。
它总是设法去除换行符,使输入一行字符串,但它从来没有设法从大串这样全歼width
和height
属性:
<li> <h1 class="liname">বীরশ্রেষ্ঠ মোস্তফা কামালঃ-</h1> <div class="iframe"><iframe src="https://www.youtube.com/embed/uZuzPrQ9X_w?&theme=dark&autohide=2&fs=0&rel=0"frameborder="0"></iframe></div> </li> <li> <h1 class="liname">বীরশ্রেষ্ঠ মতিউর রহমান:-</h1> <div class="iframe"><iframe width='500' height='294' src="https://www.youtube.com/embed/u1thP64dhrk?&theme=dark&autohide=2&modestbranding=1&fs=0&showinfo=0&rel=0"frameborder="0"></iframe></div> </li> <li> <h1 class="liname">বীরশ্রেষ্ঠ নূর মোহাম্মদ:-</h1> <div class="iframe"><iframe width='500' height='294' src="https://www.youtube.com/embed/Xjf6CO2bWW8?&theme=dark&autohide=2&modestbranding=1&fs=0&showinfo=0&rel=0"frameborder="0"></iframe></div> </li> <li> <h1 class="liname">বীরশ্রেষ্ঠ মোহাম্মদ রুহুল আমিন :-</h1> <div class="iframe"><iframe width='500' height='294' src="https://www.youtube.com/embed/CpDdMNNkkck?&theme=dark&autohide=2&modestbranding=1&fs=0&showinfo=0&rel=0"frameborder="0"></iframe></div> </li> <li> <h1 class="liname">বীরশ্রেষ্ঠ মুন্সী আবদুর রউফ:-</h1> <div class="iframe"><iframe width='500' height='294' src="https://www.youtube.com/embed/oUgsJSUHZlM?&theme=dark&autohide=2&modestbranding=1&fs=0&showinfo=0&rel=0"frameborder="0"></iframe></div> </li> <li> <h1 class="liname">বীরশ্রেষ্ঠ হামিদুর রহমান :-</h1> <div class="iframe"><iframe width='500' height='294' src="https://www.youtube.com/embed/74hSM6rGwq4?&theme=dark&autohide=2&modestbranding=1&fs=0&showinfo=0&rel=0"frameborder="0"></iframe></div> </li> <li> <h1 class="liname">বীরশ্রেষ্ঠ জাহাঙ্গীর :-</h1> <div class="iframe"><iframe width='500' height='294' src="https://www.youtube.com/embed/ctVFVaAmG7w?&theme=dark&autohide=2&modestbranding=1&fs=0&showinfo=0&rel=0"frameborder="0"></iframe></div> </li>
的上面的代码行是删除换行符后的输入。
实际的HTML代码换行符低于:
<li>
<h1 class="liname">বীরশ্রেষ্ঠ মোস্তফা কামালঃ-</h1>
<div class="iframe"><iframe src="https://www.youtube.com/embed/uZuzPrQ9X_w?&theme=dark&autohide=2&fs=0&rel=0"frameborder="0"></iframe></div>
</li>
<li>
<h1 class="liname">বীরশ্রেষ্ঠ মতিউর রহমান:-</h1>
<div class="iframe"><iframe width='500' height='294' src="https://www.youtube.com/embed/u1thP64dhrk?&theme=dark&autohide=2&modestbranding=1&fs=0&showinfo=0&rel=0"frameborder="0"></iframe></div>
</li>
<li>
<h1 class="liname">বীরশ্রেষ্ঠ নূর মোহাম্মদ:-</h1>
<div class="iframe"><iframe width='500' height='294' src="https://www.youtube.com/embed/Xjf6CO2bWW8?&theme=dark&autohide=2&modestbranding=1&fs=0&showinfo=0&rel=0"frameborder="0"></iframe></div>
</li>
<li>
<h1 class="liname">বীরশ্রেষ্ঠ মোহাম্মদ রুহুল আমিন :-</h1>
<div class="iframe"><iframe width='500' height='294' src="https://www.youtube.com/embed/CpDdMNNkkck?&theme=dark&autohide=2&modestbranding=1&fs=0&showinfo=0&rel=0"frameborder="0"></iframe></div>
</li>
<li>
<h1 class="liname">বীরশ্রেষ্ঠ মুন্সী আবদুর রউফ:-</h1>
<div class="iframe"><iframe width='500' height='294' src="https://www.youtube.com/embed/oUgsJSUHZlM?&theme=dark&autohide=2&modestbranding=1&fs=0&showinfo=0&rel=0"frameborder="0"></iframe></div>
</li>
<li>
<h1 class="liname">বীরশ্রেষ্ঠ হামিদুর রহমান :-</h1>
<div class="iframe"><iframe width='500' height='294' src="https://www.youtube.com/embed/74hSM6rGwq4?&theme=dark&autohide=2&modestbranding=1&fs=0&showinfo=0&rel=0"frameborder="0"></iframe></div>
</li>
<li>
<h1 class="liname">বীরশ্রেষ্ঠ জাহাঙ্গীর :-</h1>
<div class="iframe"><iframe width='500' height='294' src="https://www.youtube.com/embed/ctVFVaAmG7w?&theme=dark&autohide=2&modestbranding=1&fs=0&showinfo=0&rel=0"frameborder="0"></iframe></div>
</li>
什么'convert'你在这里提到吗? document.getElementById(“convert”) –
您能否提供[fiddle](https://jsfiddle.net/)? –
实际上是否从iframe中移除高度和宽度的目标是?或者是返回iframe的HTML的目标,但没有高度和宽度?对于前者,您可以使用jQuery通过删除宽度和高度属性来完成繁重的工作;对于后者,你需要.replace()或类似的。 – manassehkatz