文本在对话框中出现在一行中

时间:2015-07-24 13:53:30

标签: javascript jquery css

我无法处理来自数据库

的数据的空白区域

代码如下:

<td class="tdx" bgcolor="#CCCCCC" style="" id="sol" style="background-color:white;border-style:ridge;white-space: pre-wrap">
    <div class="dialog">
        <p>
            <%=solution%>
        </p>
    </div>
    <button class="opener">Open Dialog</button>
</td>
来自DB的<%=solution%>来自一行。我还在CSS中包含了预包装

jquery-code:

$(function() {

    $('.opener').each(function() {
        var dialog = $(this).prev('.dialog').dialog({
            autoOpen: false,
            show: {
                effect: "blind",
                duration: 1000
            },
            hide: {
                effect: "explode",
                duration: 1000
            }
        });

        $(this).click(function() {
            dialog.dialog("open");
        });
    });
});

如果我不使用对话框并检索文本区域中的文本...... 它会好起来

NODE - &gt;预包裹在小提琴中运作良好

已添加图片

enter image description here

3 个答案:

答案 0 :(得分:1)

private class UploadFileToServer extends AsyncTask<Void, Integer, String> {
    JSONObject jsonObject = null;

    @Override
    protected void onPreExecute() {

        upload_image_progress.setProgress(0);

         int totalSize = 0
        super.onPreExecute();
    }

    @Override
    protected void onProgressUpdate(Integer... progress) {
        // Making progress bar visible
        upload_image_progress.setVisibility(View.VISIBLE);
        // mHandler.sendEmptyMessageDelayed(progress[0], 100);
        // updating progress bar value
        upload_image_progress.setProgress(progress[0]);

        // updating percentage value
        // txtPercentage.setText(String.valueOf(progress[0]) + "%");
    }

    @Override
    protected String doInBackground(Void... params) {
        return uploadFile();
    }

    private String uploadFile() {

        String responseString = null;
        try {

            HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;

            HttpClient client = new DefaultHttpClient();

            SchemeRegistry registry = new SchemeRegistry();
            SSLSocketFactory socketFactory = SSLSocketFactory
                    .getSocketFactory();
            socketFactory
                    .setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);

            registry.register(new Scheme("http", socketFactory, 443));
            SingleClientConnManager mgr = new SingleClientConnManager(
                    client.getParams(), registry);
            DefaultHttpClient httpClient = new DefaultHttpClient(mgr,
                    client.getParams());

            // Set verifier
            HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);


            HttpPost httpPost = new HttpPost("your url");


            AndroidMultiPartEntity entity = new AndroidMultiPartEntity(
                    new ProgressListener() {

                        @Override
                        public void transferred(long num) {
                            publishProgress((int) ((num * 100) / totalSize));

                        }
                    });

            File sourceFile = new File("image path");
            long fileSizeInBytes = sourceFile.length();

            // Convert the bytes to Kilobytes (1 KB = 1024 Bytes)
            long fileSizeInKB = fileSizeInBytes / 1024;

            // Convert the KB to MegaBytes (1 MB = 1024 KBytes)
            long fileSizeInMB = fileSizeInKB / 1024;
            // Log.e("file length in MB", "" + fileSizeInMB);
            if (fileSizeInMB > 2) {

                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inSampleSize = 8;

                Bitmap bmp = BitmapFactory.decodeFile(image_uri, options);

                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                bmp.compress(CompressFormat.JPEG, 70, bos);
                InputStream in = new ByteArrayInputStream(bos.toByteArray());

                ContentBody foto = new InputStreamBody(in, "image/jpeg",
                        image_uri);

                Log.e("size", "" + bos.size());

                entity.addPart("image_file", foto);


                totalSize = bos.size();
                Log.e("file length", "" + sourceFile.length());

                // Adding file data to http body
            } else {
                entity.addPart("image_file", new FileBody(sourceFile));
                totalSize = entity.getContentLength();

            }

            httpPost.setEntity(entity);

            HttpResponse response = client.execute(httpPost);

            // Making server call

            HttpEntity r_entity = response.getEntity();

            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode == 200) {
                // Server response
                responseString = EntityUtils.toString(r_entity);
                jsonObject = new JSONObject(responseString);
            } else {

                responseString = "Error occurred! Http Status Code: "
                        + statusCode;
            }

        } catch (ClientProtocolException e) {
            responseString = e.toString();
            e.printStackTrace();

        } catch (IOException e) {
            e.printStackTrace();
            responseString = e.toString();

        } catch (Exception e) {
            e.printStackTrace();

        }

        return responseString;

    }

    @Override
    protected void onPostExecute(String result) {
        try {

            if (jsonObject != null) {
                //get response here
                }
        super.onPostExecute(result);
    }

}

将以上代码添加到您的CSS中。

答案 1 :(得分:0)

JSFIDDLE

您可以使用这些代码来实现您的目标。

p{
    width: 100px;
    overflow: hidden;
    -ms-text-overflow: ellipsis;
    text-overflow: ellipsis;
    white-space: nowrap;
}

答案 2 :(得分:0)

最可能的原因是错误的CSS选择器。 尝试这样的事情:

#dialog p { white-space: pre-wrap; }

由于UI使用div#dialog作为对话框内容的包装