私はドロップダウンメニューでHTMLコードを変更する方法を見つけようとしています。ドロップダウンメニューを使ってコードを自動的に変更
これは、私は現在、これは、ドロップダウンの下にあるiFrameを変更
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Languages</button>
<div id="myDropdown" class="dropdown-content">
<a href="(URL LINK)/clients/1080/Canon.html?lc=uk" target="test">English</a>
<a href="(URL LINK)/clients/1080/Canon.html?lc=de" target="test">German</a>
<a href="(URL LINK)/clients/1080/Canon.html?lc=fr" target="test">French</a>
<a href="(URL LINK)/clients/1080/Canon.html?lc=es" target="test">Spanish</a>
<a href="(URL LINK)/clients/1080/Canon.html?lc=it" target="test">Italian</a>
</div>
</div>
持っているものです。
<iframe name="test" src="(URL LINK)/clients/1080/Canon.html?lc=uk" scrolling="no" seamless="seamless"></iframe>
iFrameでは、上記のiFrameの埋め込み方法を示すプリコードがあります。
<pre><code><iframe>src="Path of the zip file" scrolling="no" seamless="seamless"></iframe>
</code></pre>
私は
/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown menu if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
を使用していJavascriptがそれはiFrameのフォルダはユーザーがドロップダウンメニューをクリックし、言語を選択することになる際に変更するホストされている場所へのリンクを実現することは可能ですか?
たとえば、ユーザーはドロップダウンメニューをクリックしてドイツ語を選択します。プリコードにはiframeが表示され、ドイツ語のフォルダへのリンクが表示されます。 (意味があることを望みます)
誰かが私を助けることができたら、非常に感謝します。
私が試した何と
を失敗したのjQuery
myFunction() {
$("#myDropdown > a").on('click', function(){
var url= $(this).attr('href'); //Get URL from a href
var $iframe = $('#iframeId'); // Get Iframe id
$iframe.attr('src',url); // Insert new URL
var v= $('#code').text(); //get Iframe inside code tags
var code = jQuery('<div />').html(v).text(); //Convert to HTML object
var n = $(code).attr("src",val); //change the src
var fin = $(n).prop("outerHTML"); //get the HTML
var finHTML = jQuery('<div />').text(fin).html(); //Convert HTML into HTML entities
$('#code').text(finHTML); // Change code HTML
});
}
のiFrame
<iframe src="#" id="iframeId"></iframe>
輸出のiFrame(テキストで)
<pre><code id="code"><iframe src="Path of the <strong>zip file downloaded from email</strong>" scrolling="no" seamless="seamless"></iframe>
</code></pre>
私は上記を試しましたが、ドロップダウンが機能しなくなりました。 はに感謝します。
... – CBroe
@CBroeリンクのクリックハンドラを追加し、そこにプリ/コード要素のinnerHTMLプロパティにhref属性の内容を書く - 、コメントについてこんにちはおかげでしたあなたは私があなたが意味するものの例を教えてくれますか?私はあなたがJavascriptで "プロ"と言うわけではありません。 – Sebbie
あなたが不明な部分を調べてから、試してみてください。問題が発生した場合は、問題を特定の問題の説明で更新してください。 – CBroe