gpt4 book ai didi

Javascript返回不适合UIWebView给定宽度和高度的内容/字符串

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:01:25 25 4
gpt4 key购买 nike

假设我的 div 中有一些字符串,

“这是我的 html 中的虚拟文本。这只是一个测试”

我会将它加载到我的 webview width=100,height=20 的 UIWebView。现在假设只有 "This is a dummy text inside" 适合 webview。

现在我希望我的 javascript 返回剩余的字符串“my html.This is just a test”(由于高度较小,不适合)。

这里我不想调整我的 webview 的大小,我只想要不适合我的 UIWebView 的剩余字符串。

任何建议将不胜感激......

                                     ***I'm newbiew to javascript...

最佳答案

使用 Below JS 函数..它将返回 Overflow 文本..

例子:

load_content('foo','Sample Text',30,100);


<script type="text/javascript">
function load_content(div_tag_id,content_string,height,width){

var text_fit = "";
var text_overflow = "";
var string_array = content_string.split(" ");

for(var i = 0; i < string_array.length; i++ ) {

document.getElementById(div_tag_id).style.width = width+"px";
document.getElementById(div_tag_id).innerHTML = document.getElementById(div_tag_id).innerHTML + " "+string_array[i];
if(document.getElementById(div_tag_id).offsetHeight > height) {
text_overflow += " "+string_array[i];
} else {
text_fit += " "+string_array[i];
}
}
document.getElementById(div_tag_id).innerHTML = text_fit;
return text_overflow;

}
</script>

关于Javascript返回不适合UIWebView给定宽度和高度的内容/字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28734559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com