($width) AND $width .= 'px';
$style = " style=\"width: $width\"";
}
$value = $value ? $value : date('H:i');
$s = " ";
return $s;
}
// form_date('start', '2018-07-05') 为空则当前日期
function form_date($name, $value = 0, $width = FALSE)
{
$style = '';
if (FALSE !== $width) {
is_numeric($width) AND $width .= 'px';
$style = " style=\"width: $width\"";
}
$value = $value ? $value : date('Y-m-d');
$s = " ";
return $s;
}
/**用法
*
* echo form_radio_yes_no('radio1', 0);
* echo form_checkbox('aaa', array('无', '有'), 0);
*
* echo form_radio_yes_no('aaa', 0);
* echo form_radio('aaa', array('无', '有'), 0);
* echo form_radio('aaa', array('a'=>'aaa', 'b'=>'bbb', 'c'=>'ccc', ), 'b');
*
* echo form_select('aaa', array('a'=>'aaa', 'b'=>'bbb', 'c'=>'ccc', ), 'a');
*/
?>组保留的标签 余下为需要删除的标签
unset($oldtag[$key]);
}
}
}
if (!empty($oldtag)) {
$tagids = array();
foreach ($oldtag as $tagid => $tagname) {
$tagids[] = $tagid;
}
well_oldtag_delete($tagids, $tid);
}
$r = well_tag_process($tid, $fid, $create_tag, $tagarr);
return $r;
}
// 删除标签和绑定的主题
function well_oldtag_delete($tagids, $tid)
{
$pagesize = count($tagids);
$arrlist = well_tag_find_by_tagids($tagids, 1, $pagesize);
$delete_tagids = array(); // 删除
$tagids = array();
$n = 0;
foreach ($arrlist as $val) {
++$n;
if (1 == $val['count']) {
// 只有一个主题
$delete_tagids[] = $val['tagid'];
} else {
$tagids[] = $val['tagid'];
}
}
!empty($delete_tagids) and well_tag_delete($delete_tagids);
$arlist = well_tag_thread_find_by_tid($tid, 1, $n);
if ($arlist) {
$ids = array();
foreach ($arlist as $val) $ids[] = $val['id'];
well_tag_thread_delete($ids);
}
!empty($tagids) and well_tag_update($tagids, array('count-' => 1));
}
// 标签数据处理 $arr=新提交的数组 $tagarr=保留的旧标签
function well_tag_process($tid, $fid, $new_tags = array(), $tagarr = array())
{
if (empty($tid)) return '';
// 新标签处理入库
if ($new_tags) {
$threadarr = array();
$tagids = array();
$i = 0;
$size = 5;
$n = count($tagarr);
$n = $n > $size ? $size : $size - $n;
foreach ($new_tags as $name) {
++$i;
$name = trim($name);
$name = stripslashes($name);
$name = strip_tags($name);
$name = str_replace(array(' ', '#', "@", "$", "%", "^", '&', '·', '<', '>', ';', '`', '~', '!', '¥', '……', ';', '?', '?', '-', '—', '_', '=', '+', '.', '{', '}', '|', ':', ':', '、', '/', '。', '[', ']', '【', '】', '‘', ' ', ' ', ' ', ' ', ' '), '', $name);
$name = htmlspecialchars($name, ENT_QUOTES);
if ($name && $i <= $n) {
// 查询标签
$read = well_tag_read_name($name);
if ($read) {
// 存在 count+1
$tagids[] = $read['tagid'];
} else {
// 入库
$arr = array('name' => $name, 'count' => 1);
$tagid = well_tag_create($arr);
FALSE === $tagid and message(-1, lang('create_failed'));
$read = array('tagid' => $tagid, 'name' => $name);
}
$tag_thread = array('tagid' => $read['tagid'], 'tid' => $tid);
$threadarr[] = $tag_thread;
$tagarr[$read['tagid']] = $read['name'];
}
}
!empty($threadarr) and tag_thread_big_insert($threadarr);
!empty($tagids) and well_tag_update($tagids, array('count+' => 1));
}
$json = empty($tagarr) ? '' : xn_json_encode($tagarr);
return $json;
}
?>return $r;
}
/**
* @param int $page 页数
* @param int $pagesize 每页显示数量
* @return mixed
*/
function link_find($page = 1, $pagesize = 100)
{
$arr = link__find($cond = array(), array('rank' => -1), $page, $pagesize);
return $arr;
}
/**
* @param $id
* @return bool 返回FALSE失败 TRUE成功
*/
function link_delete($id)
{
if (empty($id)) return FALSE;
$r = link__delete(array('id' => $id));
link_delete_cache();
return $r;
}
//--------------------------kv + cache--------------------------
/**
* @return mixed 返回全部友情链接
*/
function link_get($page = 1, $pagesize = 100)
{
$g_link = website_get('friends_link');
if (empty($g_link)) {
$g_link = link_find($page, $pagesize);
$g_link AND website_set('friends_link', $g_link);
}
return $g_link;
}
// delete kv and cache
function link_delete_cache()
{
website_set('friends_link', '');
return TRUE;
}
?> $v = implode(",", $v);
$temp[] = $v;
}
// 去掉重复的字符串,也就是重复的一维数组
$temp = array_unique($temp);
// 再将拆开的数组重新组装
$output = array();
foreach ($temp as $k => $v) {
if ($stkeep) $k = $starr[$k];
if ($ndformat) {
$temparr = explode(",", $v);
foreach ($temparr as $ndkey => $ndval) $output[$k][$ndarr[$ndkey]] = $ndval;
} else $output[$k] = explode(",", $v);
}
return $output;
}
// 合并二维数组 如重复 值以第一个数组值为准
function array2_merge($array1, $array2, $key = '')
{
if (empty($array1) || empty($array2)) return NULL;
$arr = array();
foreach ($array1 as $k => $v) {
isset($v[$key]) ? $arr[$v[$key]] = array_merge($v, $array2[$k]) : $arr[] = array_merge($v, $array2[$k]);
}
return $arr;
}
/*
* 对二维数组排序 两个数组必须有一个相同的键值
* $array1 需要排序数组
* $array2 按照该数组key排序
* */
function array2_sort_key($array1, $array2, $key = '')
{
if (empty($array1) || empty($array2)) return NULL;
$arr = array();
foreach ($array2 as $k => $v) {
if (isset($v[$key]) && $v[$key] == $array1[$v[$key]][$key]) {
$arr[$v[$key]] = $array1[$v[$key]];
} else {
$arr[] = $v;
}
}
return $arr;
}
?>
javascript - Jquery, line break in textarea.. don't get n and get ↵ - Stack Overflow-软件玩家 - 软件改变生活!
I am trying to get value of a textarea with line break. When I debug, the value is this way in jquery. the value stored in a variable like this:
"test<br>
test<br>
test"<br>
In .value of valueOf is: 'test↵test↵test'.
I wonder how can I convert it to \n in order to insert line break.. I'm using jquery to get the value and send by ajax to php!
thanks.. :)
Sorry my english..
I am trying to get value of a textarea with line break. When I debug, the value is this way in jquery. the value stored in a variable like this:
"test<br>
test<br>
test"<br>
In .value of valueOf is: 'test↵test↵test'.
I wonder how can I convert it to \n in order to insert line break.. I'm using jquery to get the value and send by ajax to php!
thanks.. :)
Sorry my english..
javascript jquery ajax textarea line-breaks
Share
Improve this question
Follow
edited
Aug 25, 2013 at 4:12
Konsole
3,475 3 3 gold badges 30 30 silver badges 41 41 bronze badges
asked
Aug 25, 2013 at 4:04
Jhonatan G.
Jhonatan G.
95 1 1 gold badge 3 3 silver badges 11 11 bronze badges
1
I think it would be better to store the text as is and then call nl2br() when needed.
– Matteo Tassinari
Commented
Aug 25, 2013 at 6:05
Add a ment
|
3 Answers
3
Sorted by:
Reset to default
3
Try this
val=document.getElementById('remend').value;
val = val.replace(/<br\s*\/?>/mg,"\n");
Fiddle http://jsfiddle/eSub4/1/
I have put a couple of console.log in fiddle to show you how new line(\n) and html line break show up in console and pare it with the text from textarea to see that you are getting new line (\n) for text in textarea after using the regex. Keep firebug open to see the output
try
document.getElementById('textareaid').innerHTML;
you need to replace 'textareaid' with the actual id.
since you say you already have the data in a string, but its not formatted right, to turn the <br> into newlines, you can use this
textString=textString.replace(/<br>/g,"\n");
It works for me....
$("#id").val("<?php echo str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),"<br>",$value); ?>".replace(/<br\s*[\/]?>/gi, "\n"));
本文标签:
JavaScriptJQuery line break in textarea don39t get n and get ↵Stack Overflow
更多相关文章 javascript - JQuery, setTimeout not working - Stack Overflow I'm still new to JQuery,on the way to getting my ajax example to work i got stalled with setTime
javascript - jquery, submit form when field loses focus - Stack Overflow How can I submit a form when a field (In this case the form only has one field) loses focus?I tried thi
JavascriptjQuery, if and else statements both being executed - Stack Overflow I'm not too sure what's going on here and feel I may be missing something that is probably qu
javascript - jQuery, why the rewind playbackRate doesn't work? - Stack Overflow I got the fast forward playbackRate work fine. Now I try with the rewind part with negative number but
javascript - Jquery, changing color on hover - Stack Overflow This has been driving me crazy for a while, I cannot figure out what I am doing wrong. I am trying to m
javascript - jQuery, CORS, JSON (without padding) and authentication issues - Stack Overflow I have two domains. I'm trying to access a JSON object from one domain through a page on another.
javascript - Jquery, line break in textarea.. don't get n and get ↵ - Stack Overflow I am trying to get value of a textarea with line break. When I debug, the value is this way in jquery.
javascript - Jquery, get label value inside a user control - Stack Overflow I need to make a calculation in an asp page with the value from a usercontrol label.the user control la
javascript - jQuery, toggle button to display plus or minus - Stack Overflow How do I toggle toggle the button to display plus or minus? The button enlarges and reduces the text. If
javascript - jQuery, Select (any all *) element on Click - Stack Overflow I'm building a debugging tool for myself. What I want it to do is place a class on any element whe
javascript - Jquery, change caret class on click - Stack Overflow I have this html code below with the caret class fa fa-caret-down. Now I want that if the user clicks o
javascript - jQuery, change 5 items at a time - Stack Overflow If I have markup like this:<li class="supress hidden"><li><li class="su
javascript - jQuery, check to see if all radiobutton groups are selected - Stack Overflow I have several radiobuttongroups, and I need to run a script when they are checked.I use the following
发表评论