内容的栏目 * @param int $category 0列表 1频道 2单页 3外链 * @return array */ function category_list($forumlist, $model = 0, $display = 0, $category = 0) { if (empty($forumlist)) return NULL; static $cache = array(); $key = $model . '-' . $display . '-' . $category; if (isset($cache[$key])) return $cache[$key]; if ($display) { foreach ($forumlist as $k => $val) { if (1 == $val['display'] && 1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } else { foreach ($forumlist as $k => $val) { if (1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } return empty($cache[$key]) ? NULL : $cache[$key]; } /** * @param $forumlist 所有版块列表 不分模型 * @param int $display 0全部CMS栏目 1在首页和频道显示内容的栏目 * @param int $category 0列表 1频道 2单页 3外链 * @return array */ function category_list_show($forumlist, $display = 0, $category = 0) { if (empty($forumlist)) return NULL; static $cache = array(); $key = $display . '-' . $category; if (isset($cache[$key])) return $cache[$key]; if ($display) { foreach ($forumlist as $k => $val) { if (1 == $val['display'] && 1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } else { foreach ($forumlist as $k => $val) { if (1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } return empty($cache[$key]) ? NULL : $cache[$key]; } /** * @param $forumlist 所有版块列表 * @return mixed BBS栏目数据(仅列表) 尚未开放bbs频道功能 */ function forum_list($forumlist) { if (empty($forumlist)) return array(); static $cache = array(); if (isset($cache['bbs_forum_list'])) return $cache['bbs_forum_list']; $cache['bbs_forum_list'] = array(); foreach ($forumlist as $_fid => $_forum) { if ($_forum['type']) continue; $cache['bbs_forum_list'][$_fid] = $_forum; } return $cache['bbs_forum_list']; } // 导航显示的版块 function nav_list($forumlist) { if (empty($forumlist)) return NULL; static $cache = array(); if (isset($cache['nav_list'])) return $cache['nav_list']; foreach ($forumlist as $fid => $forum) { if (0 == $forum['nav_display']) { unset($forumlist[$fid]); } } return $cache['nav_list'] = $forumlist; } ?>javascript - How can I replace the content of a div instead append a value using JQuery? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I replace the content of a div instead append a value using JQuery? - Stack Overflow

programmeradmin0浏览0评论

I am pretty new in JQuery and I have the following problem.

I have create this JQuery function that when the user select a file into an input tag having id=rendicontoAllegato it put the name of this file into an hidden div having id=nomeDocumentoRendicontazione into my page

$(document).ready(function() {

    $("#rendicontoAllegato").change(function() {
        alert("DOCUMENTO dopo selezione: " + $("#nomeDocumentoRendicontazione").text());

        var selectedFileName = $("#rendicontoAllegato").val();

        $('#nomeDocumentoRendicontazione').append(selectedFileName);

    });
 });

It works fine but the only problem is that if I first select something asfile1.txt and then select another file as file2.txt into the div having id=nomeDocumentoRendicontazione I will have the concatenation of the 2 files name.

So I will have something like file1.txtfile2.txt and it is not good for me.

How can I replace the value of the div having id=nomeDocumentoRendicontazione instead to append a new value inside it?

I am pretty new in JQuery and I have the following problem.

I have create this JQuery function that when the user select a file into an input tag having id=rendicontoAllegato it put the name of this file into an hidden div having id=nomeDocumentoRendicontazione into my page

$(document).ready(function() {

    $("#rendicontoAllegato").change(function() {
        alert("DOCUMENTO dopo selezione: " + $("#nomeDocumentoRendicontazione").text());

        var selectedFileName = $("#rendicontoAllegato").val();

        $('#nomeDocumentoRendicontazione').append(selectedFileName);

    });
 });

It works fine but the only problem is that if I first select something asfile1.txt and then select another file as file2.txt into the div having id=nomeDocumentoRendicontazione I will have the concatenation of the 2 files name.

So I will have something like file1.txtfile2.txt and it is not good for me.

How can I replace the value of the div having id=nomeDocumentoRendicontazione instead to append a new value inside it?

Share Improve this question asked Nov 27, 2015 at 11:50 AndreaNobiliAndreaNobili 43.1k122 gold badges361 silver badges678 bronze badges 1
  • You can use .html() or .text() or .empty().append() or .empty().prepend() .... google.co.uk/search?btnG=1&q=jquery+set+content+of+div – ahervin Commented Nov 27, 2015 at 12:00
Add a ment  | 

3 Answers 3

Reset to default 5

You can use the .text() fn if you are dealing with with your data to be inserted as text or .html() fn if you are dealing with html to be replaced

$('#nomeDocumentoRendicontazione').text(selectedFileName);

Or

$('#nomeDocumentoRendicontazione').html(selectedFileName);

Use html() instead of append().

$(document).ready(function() {

    $("#rendicontoAllegato").change(function() {
        alert("DOCUMENTO dopo selezione: " + $("#nomeDocumentoRendicontazione").text());

        var selectedFileName = $("#rendicontoAllegato").val();

        $('#nomeDocumentoRendicontazione').html(selectedFileName);

    });
 });

You have to use

 $('#nomeDocumentoRendicontazione').html(selectedFileName);

it will replace the already present HTML of that. OR you can use

 $('#nomeDocumentoRendicontazione').text(selectedFileName);

it will do the same but append your data as text.

发布评论

评论列表(0)

  1. 暂无评论