Javascript php截断字段问题
Iam正在截断php中的一个大字段。除了我在下一行中出错外,一切正常。Iam使用更多超链接截断超过25个字符。当我单击more链接时,一个javascript警报会触发实际数据Javascript php截断字段问题,javascript,php,Javascript,Php,Iam正在截断php中的一个大字段。除了我在下一行中出错外,一切正常。Iam使用更多超链接截断超过25个字符。当我单击more链接时,一个javascript警报会触发实际数据 $length_limit = 25; //limit to this number of characters $actual_length = strlen($value); //count characters in the $value $original_text = $value; $truncated_te
$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){
$value = $original_text;
} else {
$value = $truncated_text." ... <a onclick='alert(\"'.$original_text.'\")'>more</a>";
$length\u limit=25//限制此字符数
$actual_length=strlen($value)//计算$value中的字符数
$original_text=$value;
$truncated_text=substr($value,0,$length_limit);
如果($actual_length请尝试此方法
echo $value = $truncated_text." ... <a onclick=\"alert('".$original_text."')\">more</a>";
echo$value=$truncated_text.“…更多”;
您可以像下面这样做(任何人):-
echo$value=$truncated_text.“…更多”;
或
echo $value = $truncated_text." ... <a onclick=\"alert('".$original_text."')\">more</a>";
echo$value=$truncated_text.“…更多”;
弹出窗口代码:-
#编辑\u价格\u背景\u覆盖{
背景:rgba(0,0,0,1)无重复滚动0;
底部:0;
显示:无;
溢出y:自动;
位置:固定;
排名:0;
宽度:100%;
z指数:999999;
}
#新窗口{
颜色:白色;
浮动:左;
利润率:20px;
填充:100px;
文本对齐:居中;
}
您遇到了什么错误?我遇到了一个错误“SyntaxError:unterminated string literal”使用stripslashes
函数欢迎您,如果您还有疑问,请将其标记为正确。有没有办法,我可以使用一个弹出窗口来代替提醒?我可以将其作为单独的问题。我只能在3分钟后接受答案。我也会这样做。@Anant:谢谢。@SanjuMenon是的,您可以代替直接提醒,将一个函数调用到onclick中,并将数据传递给该函数,然后编写该函数,该函数将打开一个带有该函数的弹出窗口data@SanjuMenon:这取决于需求。你可以做任何事。谢谢你,阿南德。此解决方案也适用于我。:)@我也添加了弹出窗口代码。检查一下。非常感谢你的帮助。当然,我会检查一下,并让你知道这一点。再次感谢您的帮助。:)@SanjuMenon这是一个简单的弹出代码(不是花哨的)。您需要相应地修改css,使其看起来更漂亮。谢谢,欢迎。非常感谢。
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>