你可以像下面(他們中的任何一個): -
echo $value = $truncated_text.' ... <a onclick=\'alert("'.$original_text.'")\'>more</a>';
或者
echo $value = $truncated_text." ... <a onclick=\"alert('".$original_text."')\">more</a>";
彈出窗口代碼: -
<style>
#edit_price_background_overlay {
background: rgba(0, 0, 0, 1) none repeat scroll 0 0;
bottom: 0;
display: none;
overflow-y: auto;
position: fixed;
top: 0;
width: 100%;
z-index: 999999;
}
#mainnew_window {
color: white;
float: left;
margin: 20px;
padding: 100px;
text-align: center;
}
</style>
<div id="edit_price_background_overlay">
<div id="mainnew_window">
</div>
</div>
<?php
$value = 'dhgffdhgfhfhfhghgfhgfhgfhfghfghgfhgfhgfhgfgfhgfhgfhgfhgfhfgrtdyretrertertretgfdvfgvdfgdfbdfgdfbgfnbgbgfhnhhethfgbgfdnggrehgteggbfdvgfdfgergfdgfdrfgrdfgert4gtrhnfgbfdbvcvcbvcbbvcbhrgdghgyfgbfdbgfvfdbtgf';
$length_limit = 25; //limit to this number of characters
$actual_length = strlen($value); //count characters in the $value
$original_text = $value;
$truncated_text = substr($value,0,$length_limit);
if($actual_length <= $length_limit){
echo $value = $original_text;
} else {
echo $value = $truncated_text." ... <a onclick=\"showdata('".$original_text."','mainnew_window','edit_price_background_overlay')\">more</a>";
}
?>
<script>
function showdata(mytext,innerdiv,outerdiv){
var elem = document.getElementById(innerdiv);
var elem2 = document.getElementById(outerdiv);
console.log(elem);
if(typeof elem !== 'undefined' && elem !== null) {
document.getElementById(innerdiv).innerHTML = mytext;
document.getElementById(outerdiv).style.display = 'block';
}
}
</script>
注: - 把這個整個代碼php
文件,因爲它是和檢查。
你得到了什麼錯誤? –
Iam收到錯誤「SyntaxError:未終止的字符串文字」 –
使用'stripslashes'功能 –