<div>
<div>網(wǎng)盤鏈接:<span id="panLink"></span></div>
<div>提取碼:<span id="panCode"></span></div>
</div>
<script>
// 1. 定義原始文本(你提供的網(wǎng)盤分享內(nèi)容)
const originalText = "通過網(wǎng)盤分享的文件:模板編號:540 攝影科技傳媒網(wǎng)站模板.zip鏈接: https://pan.baidu.com/s/1YYJw9iwa5iKxVO15SiNZFg 提取碼: 1111 復(fù)制這段內(nèi)容后打開百度網(wǎng)盤手機App,操作更方便哦";
// 2. 提取網(wǎng)盤鏈接(匹配以https開頭,到空格結(jié)束的完整鏈接)
const linkReg = /https:\/\/pan\.baidu\.com\/s\/\S+/; // 網(wǎng)盤鏈接正則
const panLink = linkReg.exec(originalText)?.[0] || "未提取到鏈接";
// 3. 提取4位提取碼(匹配提取碼: 后面的4個字符)
const codeReg = /提取碼:\s*(\w{4})/; // 4位提取碼正則
const panCode = codeReg.exec(originalText)?.[1] || "未提取到提取碼";
// 4. 渲染到頁面,讓鏈接可點擊直接打開(target="_blank" 新窗口打開)
const linkElement = document.getElementById("panLink");
linkElement[xss_clean] = `<a href="${panLink}" target="_blank">${panLink}</a>`;
// 5. 渲染提取碼
const codeElement = document.getElementById("panCode");
codeElement.textContent = panCode;
</script>這個代碼直接在html打開,可以獲取到提取碼,但是放在模板里面,用連接打開就提取不到了
js代碼用標簽抱一下啊
{code}<script></script>{/code}回復(fù)@小波工作室
{code} <script> // 1. 定義原始文本(你提供的網(wǎng)盤分享內(nèi)容) const originalText = "{$content}"; // 2. 提取網(wǎng)盤鏈接(匹配以https開頭,到空格結(jié)束的完整鏈接) const linkReg = /https:\/\/pan\.baidu\.com\/s\/\S+/; // 網(wǎng)盤鏈接正則 const panLink = linkReg.exec(originalText)?.[0] || "未提取到鏈接"; // 3. 提取4位提取碼(匹配提取碼: 后面的4個字符) const codeReg = /提取碼:\s*(\w{4})/; // 4位提取碼正則 const panCode = codeReg.exec(originalText)?.[1] || "未提取到提取碼"; // 4. 渲染到頁面,讓鏈接可點擊直接打開(target="_blank" 新窗口打開) const linkElement = document.getElementById("panLink"); linkElement.innerHTML = `<a href="${panLink}" target="_blank">${panLink}</a>`; // 5. 渲染提取碼 const codeElement = document.getElementById("panCode"); codeElement.textContent = panCode; </script> {/code}包了以后,全都不顯示了
<script> // 1. 定義原始文本(你提供的網(wǎng)盤分享內(nèi)容) const originalText = "{$content}"; // 2. 提取網(wǎng)盤鏈接(匹配以https開頭,到空格結(jié)束的完整鏈接) const linkReg = /https:\/\/pan\.baidu\.com\/s\/\S+/; // 網(wǎng)盤鏈接正則 const panLink = linkReg.exec(originalText)?.[0] || "未提取到鏈接"; // 3. 提取4位提取碼(匹配提取碼: 后面的4個字符) const codeReg = /提取碼:\s*(\w{4})/; // 4位提取碼正則 const panCode = codeReg.exec(originalText)?.[1] || "未提取到提取碼"; // 4. 渲染到頁面,讓鏈接可點擊直接打開(target="_blank" 新窗口打開) const linkElement = document.getElementById("panLink"); {code} linkElement.innerHTML = `<a href="${panLink}" target="_blank">${panLink}</a>`; {/code} // 5. 渲染提取碼 const codeElement = document.getElementById("panCode"); codeElement.textContent = panCode; </script>const originalText = "{$content}"; 改成 const originalText = "{$title}";我記得$content不能在js里面輸出吧?